# -- coding: utf-8 --
import sys
import io

# 设置标准输出的编码为UTF-8
if sys.stdout.encoding != "UTF-8":
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
# 自动创建.env文件和环境配置
import os


def create_env_file():
    """创建.env文件"""
    env_content = """# AI开发环境配置
DEEPSEEK_API_KEY=sk-863421cfdc254a4a9246e982ff40c5ca
HUGGINGFACE_TOKEN=你的实际HuggingFace_Token

# 将上面的值替换为你的实际API密钥
# DeepSeek: https://platform.deepseek.com/
# HuggingFace: https://huggingface.co/
"""

    env_path = ".env"

    if os.path.exists(env_path):
        print("✅ .env文件已存在")
        with open(env_path, "r", encoding="utf-8") as f:
            content = f.read()
            print("当前内容:")
            print(content)
    else:
        with open(env_path, "w", encoding="utf-8") as f:
            f.write(env_content)
        print("✅ .env文件创建成功！")
        print("请编辑 .env 文件，填入你的实际API密钥")


def check_environment():
    """检查当前环境"""
    print("=== 环境检查 ===")
    print(f"当前工作目录: {os.getcwd()}")
    print(f"目录内容: {os.listdir('.')}")

    # 检查.env文件
    if os.path.exists(".env"):
        print("✅ .env文件存在")
        with open(".env", "r", encoding="utf-8") as f:
            content = f.read()
            print(".env文件内容:")
            print("-" * 30)
            print(content)
            print("-" * 30)
    else:
        print("❌ .env文件不存在")


if __name__ == "__main__":
    check_environment()
    print("\n" + "=" * 50)
    create_env_file()
